<%@page import="com.hrm.entity.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<title>用户添加页面</title>
<link href="<%=request.getContextPath()%>/css/Default.css" rel="stylesheet" type="text/css" />
<link href="<%=request.getContextPath()%>/css/redmond/jquery-ui-1.8.14.custom.css"
	rel="stylesheet" type="text/css"></link>
<link href="<%=request.getContextPath()%>/css/Dialog.css"
	rel="stylesheet" type="text/css"></link>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="<%=request.getContextPath()%>/scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/scripts/HRM.js" type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/jquery-ui-1.8.14.min.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/jquery.validate.min.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/jquery.validate.message_cn.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/Dialog.js"
	type="text/javascript"></script>
</head>
<body class="dialogBody">
<script type="text/javascript">
function beforeFormSubmitFunc(){
	var checkNum=0;
	var roleids='';//角色列表
	$("#roleTree ul").find("li").each(function(index){
		if($(this).attr('id')!=''&&($(this).attr('class').indexOf('jstree-checked')>-1)){
			checkNum++;
			roleids=roleids+$(this).attr('id')+',';
		}
	});
	if(checkNum<=0){
		createAlertDialog('提示信息','请至少选择一个角色!');
		return false;
	}
	var url=$("#userEditForm").attr('action')+'&roleids='+roleids.substring(0,roleids.length-1);
	$("#userEditForm").attr('action',url);
	if(!$("#userEditForm").valid()){
		createAlertDialog('提示信息','还有未正确填写的项，请参照提示修改!');
		return false;
	}else{
		return true;
	}
}
$().ready(function(){
	$("#userEditForm").validate({
		rules:{
			userName:{
				required:true
			}
		},
		errorPlacement:function(error,element){
			createTooltip(error,element);
		},
		success:function(error,element){
			sucRemoveTooltip(error);
		},
		event:'blur'|'keyup'|'focus'|'keydown'
	});
	$('#userEditForm').find("input").focus(function(){
		$(this).valid();
	});
	$('#userEditForm').find("input").blur(function(){
		$('#'+$(this).attr('id')+'Error').remove();
	});
	//$('#userEditForm').find('#userName').focus();
});
</script>
<form id="userEditForm" action='<%=request.getContextPath()%>/user.do?method=updateUserById' method="post">
<table width="570" height="227" align="center" cellpadding="2" cellspacing="0">
    <tr>
      <td height="10"></td>
      <td></td>
    </tr>
    <tr>
      <td width="311" >
   <fieldset>
    <legend><label>基本信息</label></legend>
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="39%" height="30" align="right" >用户名：<input name="id" type="hidden" value="<%=((User)request.getAttribute("user")).getId() %>" id="id" /></td>
          <td width="61%"><input name="userName"  type="text" id="userName" readonly value='<%=((User)request.getAttribute("user")).getUserName() %>' /><span class='requiredSpan'>*</span></td>
        </tr>
        <tr id ="tr_Password2">
          <td height="30" align="right" >创建时间：</td>
          <td><input name="createDate" type="text" id="createDate" readonly value="<%=((User)request.getAttribute("user")).getCreateDate() %>" /><span class='requiredSpan'>*</span></td>
        </tr>
        <tr id ="tr_ConfirmPassword2">
          <td height="30" align="right" >创建人：</td>
          <td><input name="createUserName" type="text" id="createUserName" readonly value="<%=((User)request.getAttribute("user")).getCreateUserName() %>"/><span class='requiredSpan'>*</span></td>
        </tr>
        <tr>
          <td height="30" align="right" >真实姓名：</td>
          <td><input name="realName"  type="text" value="" id="realName"  readonly/></td>
        </tr>
        <tr>
          <td height="30" align="right" >是否停用：</td>
          <td ><input type='radio' name='Status' id='Status_0' value='N' checked readonly><label for='Status_0'>正常</label><input type='radio' name='Status' id='Status_1' value='S' readonly><label for='Status_1'>停用</label></td>
        </tr>
        <tr>
          <td height="30" align="right" >电子邮件：</td>
          <td><input name="Email"  type="text"  id="Email" value="" readonly/></td>
        </tr>
        <tr>
          <td height="30" align="right" >联系电话：</td>
          <td><input name="Tel"  type="text" value=""  id="Tel" readonly/>
            <br>01012345678(示例)</td>
        </tr>
        <tr>
          <td height="30" align="right" >手机号码：</td>
          <td><input name="Mobile"  type="text" value=""  id="Mobile" readonly/>
            <br>13912345678(示例)</td>
        </tr>
        <tr>
          <td height="30" align="right" >备注：</td>
          <td><input name="Memo" type="text"  id="Memo" value="" readonly/></td>
        </tr>
      </table></fieldset></td>
      <td  width="270"  valign="top">
	  <fieldset>
		<legend><label>所属角色</label></legend>
		  <table width="100%" border="0" cellpadding="2" cellspacing="0">
			<tr>
			<td>
			<div class="treeItem" id="roleTree" style="width:100%;height:275px;"></div>
			<script
	src="<%=request.getContextPath()%>/scripts/jstree/jquery.jstree.js"
	type="text/javascript"></script>

<script type="text/javascript">
		$().ready(function(){
			var checkboxs=[];
			$("#roleTree").jstree({//角色树
		        "json_data" : {
		            "ajax" : {
		                	"url" : "<%=request.getContextPath()%>/role.do?method=getRoleTree&userId=<%=((User)request.getAttribute("user")).getId() %>",
							 "success":function(data){
								 checkboxs= data['checkboxs'];//获取初始化选中用户所属的角色数组
							 }
		            		}
						},
				"checkbox":{
					"checked_parent_open":false
				},
				"plugins" : [ "themes",
						"json_data","checkbox" ]
			});
			$("#roleTree").bind("loaded.jstree", function (e, data) {//初始化选中用户所属的角色
				$.each(checkboxs,function(n){
					 $('#'+checkboxs[n]).find(".jstree-checkbox").click();
				 });
			});
		});
	</script>
		</td>
		 </tr>
      </table></fieldset>
	  </td>
    </tr>
	</table>
</form>

</body>
</html>